<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取一个环境变量的值</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-required-files.html">get_required_files</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.getlastmod.html">getlastmod</a></div>
 <div class="up"><a href="ref.info.html">PHP 选项/信息 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.getenv" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">getenv</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">getenv</span> &mdash; <span class="dc-title">获取一个环境变量的值</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.getenv-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>getenv</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$varname</code></span>
   )</div>

  <p class="para rdfs-comment">
   获取一个环境变量的值。
  </p>
  <p class="para">
   使用 <span class="function"><a href="function.phpinfo.html" class="function">phpinfo()</a></span> 你可以看到所有环境变量的列表。
   这些变量很多都在 <a href="http://www.faqs.org/rfcs/rfc3875" class="link external">&raquo;&nbsp;RFC 3875</a> 的范围之内，
   尤其是章节4.1，&quot;Request Meta-Variables&quot;。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.getenv-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">varname</code></em></dt>

     <dd>

      <p class="para">
       变量名。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.getenv-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回环境变量 <em><code class="parameter">varname</code></em> 的值，
   如果环境变量 <em><code class="parameter">varname</code></em> 不存在则返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.getenv-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-467">
    <p><strong>Example #1 <span class="function"><strong>getenv()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;getenv()&nbsp;使用示例<br /></span><span style="color: #0000BB">$ip&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">getenv</span><span style="color: #007700">(</span><span style="color: #DD0000">'REMOTE_ADDR'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;或简单仅使用全局变量（$_SERVER&nbsp;或&nbsp;$_ENV）<br /></span><span style="color: #0000BB">$ip&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'REMOTE_ADDR'</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.getenv-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.putenv.html" class="function" rel="rdfs-seeAlso">putenv()</a> - 设置环境变量的值</span></li>
    <li class="member"><span class="function"><a href="function.apache-getenv.html" class="function" rel="rdfs-seeAlso">apache_getenv()</a> - Get an Apache subprocess_env variable</span></li>
    <li class="member"><a href="language.variables.superglobals.html" class="link">超全局变量</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-required-files.html">get_required_files</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.getlastmod.html">getlastmod</a></div>
 <div class="up"><a href="ref.info.html">PHP 选项/信息 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
